# -*- coding: utf-8 -*-
"""
Created on Thu May 16 20:20:54 2019

@author: yaoyu
"""

def ask(prompt = "Do you like Python? ", hint = "yes or no"):
    while True:
        answer = input(prompt)
        if answer.lower() in ('y', 'yes'):
            print("Thank you")
            return True
        if answer.lower() in ('n', 'no'):
            print("Why not")
            return False
        else:
            print(hint)

def fib(n):
    a, b = 0, 1
    count = 1
    while count  < n:
        a, b = b, a+b
        count = count + 1
    return b


if 0:
    l = [1, 2, 3, 4]; l.reverse()
    print(l)

    l = [1, 2, 3, 4]; l.pop()
    print(l.index(3))

    l = [1, 2, 3, 4]; l.pop(1)
    print(l)


    l = [1, 2, 3, 4]; l.insert(2, -1)
    print(l)


    l = [2, 1, 3, 5, 4]; l.remove(3); l.sort();
    print(l)


    scores = {'Jack': 90, 'Mike': 80, 'Jay': 85, 'Bill': 60}; s = dict(Jack=90, Mike=80, Jay=85, Bill=60); scores == s
    scores = {'Jack': 90, 'Mike': 80, 'Jay': 85, 'Bill': 60}; del scores['Bill']; len(scores)

    (1, 2, 3, 4) < (1, 2, 4)


    def compute(*numbers):
        s = 1
        for n in numbers:
            s = s * n + n
        return s


    def ask(prompt, hint = "yes or no", chance = 2):
        while chance > 0:
            answer = input(prompt)
            if answer.lower() in ('y', 'yes'):
                print("Thank you")
                return True
            if answer.lower() in ('n', 'no'):
                print("Why not")
                return False
            else:
                chance -= 1
                print(hint)
        print("Sorry, you have tried too many times.")

    #ask("Do you like SciPy?")
    '''
    Do you like SciPy? What?
    yes or no

    Do you like SciPy? en
    yes or no
    Sorry, you have tried too many times.
    '''

    fp = open('test.txt', 'rb+', 0)
    fp.readline()
    fp.seek(10, 1)
    print(fp.readline())
    fp.close()



fruits = ['apple', 'banana', 'cherry','banana', 'peach', 'pear','peach', 'cherry' ]
d = {}
for item in fruits:
    d[item] = fruits.count(item)

d = {}
for item in fruits:
    d[item] = d.get(item, 0) + 1
print(d)